import Vue from 'vue'

const PopConstructor = Vue.extend(require('./pop.vue'))

const instance = new PopConstructor({
  el: document.createElement('div')
})
PopConstructor.prototype.close = function () {
  const el = instance.$el
  el.parentNode && el.parentNode.removeChild(el)
}
PopConstructor.prototype.closePop = function (stay, callback) {
  typeof callback === 'function' && callback()

  if (stay) {
    return
  }

  const el = instance.$el
  instance.mes = ''
  instance.title = ''
  instance.tip = false
  instance.opts = []
  el.parentNode && el.parentNode.removeChild(el)
}

const show = (options = {}) => {
  instance.mes = options.mes || ''
  instance.title = options.title || ''
  instance.tip = options.tip || false
  instance.opts = options.opts
  document.body.appendChild(instance.$el)
}

export default {
  close: instance.close,
  show
}
